package com.generator.GenTemplateManage.controller;


import lombok.AllArgsConstructor;
import com.generator.GenTemplateManage.entity.GenTemplateManageEntity;
import com.generator.GenTemplateManage.service.GenTemplateManageService;
import org.springframework.web.bind.annotation.*;

import net.maku.generator.common.page.PageResult;
import net.maku.generator.common.utils.Result;

import javax.validation.Valid;
import java.util.Arrays;

/**
* 模板管理
*
* @author huej huejTest@qq.com
* @since 1.0.0 2022-08-25
*/
@RestController
@RequestMapping("GenTemplateManage/gentemplatemanage")
@AllArgsConstructor
public class GenTemplateManageController {
    private final GenTemplateManageService genTemplateManageService;

    @GetMapping("page")
    public Result<PageResult<GenTemplateManageEntity>> page(@RequestBody GenTemplateManageEntity entity){
        PageResult<GenTemplateManageEntity> page = genTemplateManageService.page(entity);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    public Result<GenTemplateManageEntity> get(@PathVariable("id") Long id){
        GenTemplateManageEntity entity = genTemplateManageService.getById(id);

        return Result.ok(entity);
    }

    @PostMapping
    public Result<String> save(@RequestBody GenTemplateManageEntity entity){
        genTemplateManageService.save(entity);

        return Result.ok();
    }

    @PutMapping
    public Result<String> update(@RequestBody @Valid GenTemplateManageEntity entity){
        genTemplateManageService.updateById(entity);

        return Result.ok();
    }

    @DeleteMapping
    public Result<String> delete(@RequestBody Long[] ids){
        genTemplateManageService.removeBatchByIds(Arrays.asList(ids));

        return Result.ok();
    }
}
